#!/usr/bin/python
import smtplib
import getpass
import socket
from smtplib import SMTPException


username = getpass.getuser() 
hostname = socket.gethostname()


sender = username+"@"+hostname
receivers = ['dong.zhao1@motorolasolutions.com']

message_header = '"""'
message_from = 'From: From '+username + '<' + username + '@' + hostname + '>\n'
message_to = 'To: To ' + receivers[0].split("@")[0] + ' ' + receivers[0]
message_subject = '\nSubject: ' +'This is a failure notification test'
message_footer = '"""'


print message_header
print message_from
print message_to
print message_subject
print message_footer


#message = """From: From Person <from@fromdomain.com>
#To: To Person <to@todomain.com>
#Subject: Keepalived failure notification
#This is a failure notification e-mail message!
#"""

message = message_header + message_from + message_to + message_subject + message_footer

print message

try:
   smtpObj = smtplib.SMTP('localhost')
   smtpObj.sendmail(sender, receivers, message)
   print "Successfully sent email"
except SMTPException:
   print "Error: unable to send email"      

